home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 353_02 / date.h < prev    next >
C/C++ Source or Header  |  1992-01-18  |  2KB  |  56 lines

  1.                                // Chapter 5 - Program 10
  2.  
  3. // This date class is intended to illustrate how to write a non-
  4. //  trivial class in C++.  Even though this class is non-trivial,
  5. //  it is still simple enough for a new C++ programmer to follow
  6. //  all of the details.
  7.  
  8. #ifndef DATE_H
  9. #define DATE_H
  10.  
  11. class date {
  12. protected:
  13.    int month;                  // 1 through 12
  14.    int day;                    // 1 through max_days
  15.    int year;                   // 1500 through 2200
  16.    static char out_string[25]; // Format output area
  17.    static char format;         // Format to use for output
  18.  
  19.          // Calculate how many days are in any given month
  20.          // Note - This is a private method which can be called only
  21.          //        from within the class itself
  22.    int days_this_month(void);
  23.  
  24. public:
  25.          // Constructor - Set the date to the current date and set
  26.          //               the format to 1
  27.    date(void);
  28.  
  29.          // Set the date to these input parameters
  30.          //  if return = 0 ---> All data is valid
  31.          //  if return = 1 ---> Something out of range
  32.    int set_date(int in_month, int in_day, int in_year);
  33.  
  34.          // Get the month, day, or year of the stored date
  35.    int get_month(void) { return month; };
  36.    int get_day(void)   { return day;   };
  37.    int get_year(void)  { return year;  };
  38.  
  39.          // Select the desired string output format for use when the
  40.          //  get_date_string is called
  41.    void set_date_format(int format_in) { format = format_in; };
  42.  
  43.          // Return an ASCII-Z string depending on the stored format
  44.          //   format = 1    Aug 29, 1991
  45.          //   format = 2    8/29/91
  46.          //   format = 3    8/29/1991
  47.          //   format = 4    29 Aug 1991    Military time
  48.          //   format = ?    Anything else defaults to format 1
  49.    char *get_date_string(void);
  50.  
  51.          // Return Jan Feb Mar Apr etc.
  52.    char *get_month_string(void);
  53. };
  54.  
  55. #endif
  56.